package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper extends BaseMapper<Student> {
    @Override
    @Select("select student_id,student_name,gender,cla_id,hostel_id,major_id from student ${ew.customSqlSegment}")
    @Results({
            @Result(property = "studentId", column = "student_id"),
            @Result(property = "studentName", column = "student_name"),
            @Result(property = "cla", column = "cla_id", javaType = Cla.class,
                    one = @One(select = "com.zyg.dao.ClaMapper.selectById")),
            @Result(property = "hostel", column = "hostel_id", javaType = Hostel.class,
                    one = @One(select = "com.zyg.dao.HostelMapper.selectById")),
            @Result(property = "major", column = "major_id", javaType = Major.class,
                    one = @One(select = "com.zyg.dao.MajorMapper.selectById"))
    })
    List<Student> selectList(IPage<Student> page, @Param(Constants.WRAPPER) Wrapper<Student> queryWrapper);
    @Select("select m.major_name as name,count(*) as value  from  student s inner join major m on m.major_id = s.major_id group by s.major_id order by value ")
    public List<EchartsData> getMajorIndexData() ;
    @Select("select c.cla_name as name,count(*) as value  from  student s inner join sys_cla c on c.cla_id = s.cla_id group by s.cla_id  ")
    public List<EchartsData> getClaIndexData() ;
    @Select("select h.hostel_name as name,count(*) as value  from  student s inner join hostel h on h.hostel_id = s.hostel_id group by s.hostel_id order by value ")
    public List<EchartsData> getHostelIndexData() ;
}
